package de.QuizCommunity.service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;


import de.QuizCommunity.domain.Bewertung;

public class Bewertung_Put {
	public static void postBewerung(Bewertung bewertung) {
		// Create a new HttpClient and Post Header
		HttpClient httpclient = new DefaultHttpClient();
		HttpPost httppost = new HttpPost(
				"http://www.iwi.hs-karlsruhe.de/ebatc/QuizCommunity/rest/webservice/bewertung");

		try {
			// Add your data

			List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
			
			 nameValuePairs.add(new BasicNameValuePair("benutzerId",""+bewertung.getBenutzerId()));
			 nameValuePairs.add(new BasicNameValuePair("wert",""+bewertung.getWert()));
			 nameValuePairs.add(new BasicNameValuePair("kommentar",bewertung.getKommentar()));
			 nameValuePairs.add(new BasicNameValuePair("frageId",""+bewertung.getFrageId()));
			
			httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
			httppost.setHeader("Content-type",
					"application/x-www-form-urlencoded; charset=UTF8");

			// Execute HTTP Post Request
			HttpResponse response = httpclient.execute(httppost);

		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
		} catch (IOException e) {
			// TODO Auto-generated catch block
		}
	}

}
